﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Modules.guide.actions {
    import flash.events.*;
    import Display.DialogUI.*;
    import Display.*;
    import Modules.guide.ui.*;

    public class GADisplayDialog extends GuideAction {

        public static const TYPE_WELCOME:String = "welcome";
        public static const TYPE_GUIDE:String = "guide";
        public static const TYPE_CHARACTER:String = "character";
        public static const TYPE_INVITE_FRIENDS:String = "inviteFriends";
        public static const TYPE_GUIDE_NEW_GUIDER:String = "guide_new_guider";

        protected var m_buttonName:String = "";
        protected var m_dialog:GenericDialog = null;
        protected var m_modal:Boolean = false;
        protected var m_position:int = 0;
        protected var m_offsetX:Number = 0;
        protected var m_offsetY:Number = 0;
        protected var m_avatarOffsetX:Number = 0;
        protected var m_avatarOffsetY:Number = 0;
        protected var m_callback:Function = null;
        protected var m_message:String = "test message";
        protected var m_title:String = "test title";
        protected var m_textPackage:String = "Tutorials";
        protected var m_titleKey:String = "";
        protected var m_hint:String = "test hint";
        protected var m_type:String;
        protected var m_avatar:String;
        protected var m_avatarLocation:String;
        protected var m_titleFontSize:Number = 20;
        protected var m_titleSmallCapsFontSize:Number = 30;

        override public function createFromXml(_arg1:XML):Boolean{
            var _local2:XMLList = checkAndGetElement(_arg1, "dialog");
            if (!_local2){
                return (false);
            };
            var _local3:String = _local2.@text;
            var _local4:String = _local2.@type;
            var _local5:String = _local2.@button;
            var _local6:String = _local2.@callback;
            var _local7:String = _local2.@modal;
            var _local8:String = _local2.@position;
            var _local9:String = _local2.@offsetX;
            var _local10:String = _local2.@offsetY;
            var _local11:String = _local2.@avatarOffsetX;
            var _local12:String = _local2.@avatarOffsetY;
            this.m_titleFontSize = ((String(_local2.@titleFontSize).length > 0)) ? _local2.@titleFontSize : 20;
            this.m_titleSmallCapsFontSize = ((String(_local2.@titleSmallCapsFontSize).length > 0)) ? _local2.@titleSmallCapsFontSize : 30;
            this.m_textPackage = ((_local2.attribute("textPackage").length() > 0)) ? _local2.@textPackage : "Tutorials";
            this.m_avatar = _local2.@avatar;
            this.m_avatarLocation = ((_local2.attribute("avatarLocation").length() > 0)) ? _local2.@avatarLocation : "right";
            this.m_type = _local4;
            this.m_message = ZLoc.t(this.m_textPackage, _local3, {name:Global.player.firstName});
            this.m_title = ZLoc.t(this.m_textPackage, (_local3 + "_title"));
            this.m_titleKey = _local3;
            if (_local5.length > 0){
                this.m_buttonName = _local5;
            };
            if (_local6.length > 0){
            };
            if ((((_local7.length > 0)) && ((_local7.toLowerCase() == "true")))){
                this.m_modal = true;
            } else {
                this.m_modal = false;
            };
            if (_local8.length > 0){
                _local8 = _local8.toLowerCase();
                switch (_local8){
                    case "center":
                    default:
                        this.m_position = GuideDialog.POS_CENTER;
                        break;
                    case "nw":
                        this.m_position = GuideDialog.POS_NW;
                        break;
                    case "ne":
                        this.m_position = GuideDialog.POS_NE;
                        break;
                    case "sw":
                        this.m_position = GuideDialog.POS_SW;
                        break;
                    case "se":
                        this.m_position = GuideDialog.POS_SE;
                        break;
                    case "abs":
                        this.m_position = GuideDialog.POS_ABS;
                };
            } else {
                this.m_position = GuideDialog.POS_CENTER;
            };
            if (_local9.length > 0){
                this.m_offsetX = Number(_local9);
            };
            if (_local10.length > 0){
                this.m_offsetY = Number(_local10);
            };
            if (_local11.length > 0){
                this.m_avatarOffsetX = Number(_local11);
            };
            if (_local12.length > 0){
                this.m_avatarOffsetY = Number(_local12);
            };
            return (true);
        }
        override public function enter():void{
            var _local1:Object;
            switch (this.m_type){
                case TYPE_GUIDE_NEW_GUIDER:
                    this.m_dialog = new NewGuiderDialog(this.m_message, this.m_title, 0, null, true, this.m_avatar, this.m_hint);
                    this.m_dialog.addEventListener(Event.CLOSE, this.onDialogClose, false, 0, true);
                    break;
                case TYPE_WELCOME:
                    this.m_dialog = new WelcomeDialog(this.m_message, this.m_title, 0, null, true, this.m_avatar, this.m_hint);
                    this.m_dialog.addEventListener(Event.CLOSE, this.onDialogClose, false, 0, true);
                    break;
                case TYPE_INVITE_FRIENDS:
                    this.m_dialog = new InviteFriendsGuideDialog(this.m_message, this.m_title, 0, null, true, this.m_avatar, this.m_hint);
                    this.m_dialog.addEventListener(Event.CLOSE, this.onDialogClose, false, 0, true);
                    break;
                case TYPE_CHARACTER:
                    _local1 = {
                        titleFontSize:this.m_titleFontSize,
                        titleSmallCapsFontSize:this.m_titleSmallCapsFontSize
                    };
                    this.m_dialog = new CharacterDialog(this.m_message, this.m_titleKey, 0, null, null, true, this.m_avatar, this.m_buttonName, _local1);
                    this.m_dialog.addEventListener(Event.CLOSE, this.onDialogClose, false, 0, true);
                    break;
                case TYPE_GUIDE:
                default:
                    this.m_dialog = new GuideDialog(this.m_message, this.m_title, this.m_buttonName, this.m_modal, this.m_position, this.m_offsetX, this.m_offsetY, this.m_avatar, this.m_avatarOffsetX, this.m_avatarOffsetY, this.m_avatarLocation);
                    removeState(this);
            };
            UI.displayPopup(this.m_dialog);
            m_guide.trackDialog(this.m_dialog);
            super.enter();
        }
        private function onDialogClose(_arg1:Event):void{
            this.m_dialog.removeEventListener(Event.CLOSE, this.onDialogClose);
            super.removeState(this);
        }
        override protected function allAssetsLoaded():Boolean{
            return (this.m_dialog.hasLoaded());
        }

    }
}//package Modules.guide.actions 
